﻿#include "OperTool.h"
#include "FITK_Kernel/FITKAppFramework/FITKGlobalData.h"
#include "FITK_Kernel/FITKAppFramework/FITKAppFramework.h"
#include "OperatorsInterface/GraphEventOperator.h"
#include <QWidget>
#include <QVariant>

#include "GUIDialog/GUIToolDialog/GUITranslateDialog.h"
#include "GUIDialog/GUIToolDialog/GUIRotationDialog.h"
#include "GUIDialog/GUIToolDialog/GUIScaleDialog.h"
#include "GUIDialog/GUIToolDialog/GUIMirrorDialog.h"
#include "GUIDialog/GUIToolDialog/GUIRectangularDialog.h"

bool ModelOper::OperTool::execGUI(){
    //获取动作名称
    QString actionName = _emitter->objectName();
    if (actionName == "actionToolTranslate")
    {
        this->createTranslateOper();
    }
    else if (actionName == "actionToolRotation")
    {
        this->createRotationOper();
    }
    else if (actionName == "actionToolScale")
    {
        this->createScaleOper();
    }
    else if (actionName == "actionToolMirror")
    {
        this->createMirrorOper();
    }
    else if (actionName == "actionToolArray")
    {
        this->createArrayOper();
    }
    return false;
}

bool ModelOper::OperTool::execProfession()
{  
    QVariant objIDData;
    if (!this->argValue("objID", objIDData)) return false;
    //获取三维可视对象数据-用于渲染数据对象
    EventOper::GraphEventOperator* graphOper = FITKOPERREPO->getOperatorT<EventOper::GraphEventOperator>("GraphPreprocess");
    if (graphOper == nullptr)return false;
    bool ok = false;
    int objID = objIDData.toInt(&ok);
    if (ok)
        graphOper->updateGraph(objID, true);
    else
    {
        QList<QVariant> objIDList = objIDData.toList();
        for(QVariant id : objIDList)
            graphOper->updateGraph(id.toInt(), true);
    }
    return true;
}

bool ModelOper::OperTool::createTranslateOper()
{
    //主界面
    QWidget* mw = FITKAPP->getGlobalData()->getMainWindow();
    if (!mw) return false;
    //创建界面
    GUI::GUITranslateDialog* dialog = new GUI::GUITranslateDialog(this,mw);

    //当界面执行完毕后执行
    connect(dialog, &QDialog::accepted, this, &OperTool::execProfession);
    dialog->show();
    return true;
}

bool ModelOper::OperTool::createRotationOper()
{
    //主界面
    QWidget* mw = FITKAPP->getGlobalData()->getMainWindow();
    if (!mw) return false;
    //创建界面
    GUI::GUIRotationDialog* dialog = new GUI::GUIRotationDialog(this, mw);

    //当界面执行完毕后执行
    connect(dialog, &QDialog::accepted, this, &OperTool::execProfession);
    dialog->show();
    return true;
}

bool ModelOper::OperTool::createScaleOper()
{
    //主界面
    QWidget* mw = FITKAPP->getGlobalData()->getMainWindow();
    if (!mw) return false;
    //创建界面
    GUI::GUIScaleDialog* dialog = new GUI::GUIScaleDialog(this, mw);

    //当界面执行完毕后执行
    connect(dialog, &QDialog::accepted, this, &OperTool::execProfession);
    dialog->show();
    return true;
}

bool ModelOper::OperTool::createMirrorOper()
{
    //主界面
    QWidget* mw = FITKAPP->getGlobalData()->getMainWindow();
    if (!mw) return false;
    //创建界面
    GUI::GUIMirrorDialog* dialog = new GUI::GUIMirrorDialog(this, mw);

    //当界面执行完毕后执行
    connect(dialog, &QDialog::accepted, this, &OperTool::execProfession);
    dialog->show();
    return true;
}

bool ModelOper::OperTool::createArrayOper()
{
    //主界面
    QWidget* mw = FITKAPP->getGlobalData()->getMainWindow();
    if (!mw) return false;
    //创建界面
    GUI::GUIRectangularDialog* dialog = new GUI::GUIRectangularDialog(this, mw);

    //当界面执行完毕后执行
    connect(dialog, &QDialog::accepted, this, &OperTool::execProfession);
    dialog->show();
    return true;
}

